package webserver;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Map;

public class WebServer {
	
	private void serverStart(int port,String workSpace) {
		ServerSocket serverSocket = null;
		try {
			serverSocket = new ServerSocket(port);
			while(true) {
				Socket socket = serverSocket.accept();
				new Processor(socket,workSpace).start();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		String xmlPath = XmlUtils.class.getResource("").toString()+"server.xml";
		xmlPath = xmlPath.replaceAll("file:/", "");
		Map<String,String> map = null;
		try {
			map = XmlUtils.serverXml(xmlPath);
		} catch (Exception e) {
			e.printStackTrace();
		}
		String portStr = map.get("port");
		new WebServer().serverStart(Integer.parseInt(portStr),map.get("workSpace"));
	}
}
